package com.hailong.hadoop.rpc.protobuf.server;

import com.google.protobuf.BlockingService;
import com.hailong.hadoop.rpc.protobuf.MyResourceTrackerPB;
import com.hailong.hadoop.rpc.protobuf.MyResourceTrackerServerSidePB;
import com.hailong.hadoop.rpc.protobuf.MyResourceTrackerService;
import com.hailong.hadoop.rpc.protobuf.proto.MyResourceTracker;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.ProtobufRpcEngine;
import org.apache.hadoop.ipc.RPC;

/**
 * Created by 31464 on 2022/1/11.
 */
public class ProtobufRPCServer {
    public static void main(String[] args)  throws Exception{

        String hostname="localhost";
        int port=8888;
        Configuration config=new Configuration();
        RPC.setProtocolEngine(config,MyResourceTrackerPB.class, ProtobufRpcEngine.class);

        RPC.Server server = new RPC.Builder(config)
                .setProtocol(MyResourceTrackerPB.class)
                .setInstance((BlockingService) MyResourceTracker.MyResourceTrackerService.newReflectiveBlockingService(new MyResourceTrackerServerSidePB(new MyResourceTrackerService())))
                .setBindAddress(hostname)
                .setNumHandlers(1)
                .setVerbose(true)
                .build();

        System.out.println("服务端启动......");
        server.start();


    }
}
